package com.example.hangzhou.welbeing.mytestdemoapp.adpater;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.hangzhou.welbeing.mytestdemoapp.R;

/**
 * 杭州惟君医疗科技有限公司13
 * Created by 20433 on 2018/5/15
 *
 * @desc 东风山河绿，春已不折柳，繁花看不尽，处处惹人留
 * @desc 佛祖镇楼，bug辟容易
 */

public class MyDialogAdapter extends RecyclerView.Adapter<MyDialogAdapter.ViewHolder> implements View.OnClickListener{

    private String[] arr = new String[]{"普通的Dialog","自定义Dialog01","自定义Dialog02","自定义Dialog03","自定义Dialog04","自定义Dialog05","自定义Dialog06","自定义Dialog07"};
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_my_dialog, parent, false);
        // 实例化
        ViewHolder viewHolder = new ViewHolder(v);
        v.setOnClickListener(this);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.tv_content.setText(arr[position]);
    }

    @Override
    public int getItemCount() {
        return arr.length;
    }

    @Override
    public void onClick(View view) {
        if(mListener != null){
            mListener.onItemClick(view);
        }
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        TextView tv_content;
        ImageView iv_phone;

        public ViewHolder(View itemView) {
            super(itemView);
            tv_content = (TextView) itemView.findViewById(R.id.item_my_dialog_tv_content);
            iv_phone = (ImageView) itemView.findViewById(R.id.item_my_dialog_iv_phone);
        }
    }
    public  interface OnItemClickListener {
        void onItemClick(View view);
    }
    private OnItemClickListener mListener;

    public void setOnItemClickListener(OnItemClickListener li) {
        mListener = li;
    }

}
